package com.zisu.wcsopcua.opcua.selfunion;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class Test2 {
    public static void main(String[] args) throws Exception {/*
        UAService uaService = new UAService();
        *//*boolean valueByName = uaService.setValue(PLCVar.INT32_3,11);
        System.out.println("before:"+valueByName);*//*
        long start = System.currentTimeMillis();
        uaService.setValue(PLCVar.Boolean_3,true);
        long end = System.currentTimeMillis();
        System.out.println("after:need time ："+(end-start));*/

        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "101";
        });
        CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> 100);

        //s 参数是主体，，i 是future的结果。  并且会等 future1、future2 都完成了。
        CompletableFuture<Double> future = future1.thenCombine(future2, (s, i) -> Double.parseDouble(s + i));

        try {
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
